package com.kgis.map.control.basemaptool {
    import com.kgis.map.Map;
    import com.kgis.map.control.ILegendDisplayControlAware;
    import com.kgis.map.control.LegendDisplayControl;
    import com.kgis.map.events.MapEvent;

    import mx.controls.Image;
    import mx.core.Application;
    import mx.core.FlexGlobals;
    import mx.managers.PopUpManager;
    import com.kgis.map.control.basemaptool.AbstractBaseMapTool;

    public class LegendControl extends AbstractBaseMapTool {
        private var legend:LegendDisplayControl;

        public function LegendControl(value:Map) {
            super(value);
        }

        override public function execute():void {
            legend = this.map.legendControl as LegendDisplayControl;
            if (legend && legend.isPopUp && legend.visible) {

            }
            else {
                legend = new LegendDisplayControl();
                this.map.legendControl = legend;
                legend.x = this._map.width - legend.width - 10;
                legend.y = 50;
                if (!legend.visible) {
                    legend.visible = true;
                    PopUpManager.addPopUp(legend, this._map, false);
                    var mapEvent:MapEvent = new MapEvent(MapEvent.MOVE_END, map);
                    mapEvent.oldZoom = 0;
                    mapEvent.newZoom = map.zoom;
                    legend.mapZoomLevelChangedHandler(mapEvent);
                }
            }
        }

    }
}